home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu219.dms / pu219.adf / SOURCES / esuoM.c < prev    next >
C/C++ Source or Header  |  1992-07-16  |  5KB  |  126 lines

  1. /****************************************************************
  2.  *
  3.  *                   esuoM - Backwards Mouse
  4.  *
  5.  *    This program installs an input handler which will reverse
  6.  *    all mouse movements and cause the mouse pointer to move in
  7.  *    the opposite direction of the mouse.
  8.  *
  9.  ****************************************************************/
  10. #include <intuition/intuitionbase.h>
  11. #include <devices/input.h>
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14.  
  15. #define PORTNAME "-=+RBE_esuoM+=-"
  16.  
  17. struct InputEvent *hndcode();    /* input handler function   */
  18. void hndstub();                  /* asm stub for interfacing */
  19.  
  20. struct Interrupt handlerptr;     /* Interrupt struct for installing handler */
  21. struct MsgPort *inputport;       /* msg port for IO request     */
  22. struct IOStdReq *inputreq;       /* IO request for input device */
  23. struct Message *m;               /* to get Intui messages       */
  24. extern struct IntuitionBase *IntuitionBase;
  25.  
  26. struct Window *mywindow;           /* opened window  */
  27. struct NewWindow mynewwindow =     /* to create new window - for the  */
  28. { 150, 50,     /* left, top */     /* sole purpose of getting close   */
  29.   125, 10,     /* width, height */ /* window message                  */
  30.   -1, -1,      /* pens */
  31.   CLOSEWINDOW, /* IDCMP */
  32.   WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | SMART_REFRESH | NOCAREREFRESH |
  33.   RMBTRAP,     /* flags */
  34.   NULL, NULL,  /* gadgets, checkmark */
  35.   "esuoM",     /* title */
  36.   NULL, NULL,  /* screen, bitmap */
  37.   0, 0, 0, 0,  /* min, max sizes */
  38.   WBENCHSCREEN /* screen type */
  39. };
  40.  
  41. void _main()       /* _main instead of main to save space (Lattice) */
  42. {
  43.   int waitmask, done;
  44.  
  45.   if (FindPort(PORTNAME) != NULL)  /* look to see if already installed - */
  46.     exit(99);                      /* will not install more than once    */
  47.  
  48.   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  49.   inputport = CreatePort(PORTNAME,0);  /* make port for IO req */
  50.   if (IntuitionBase== NULL || inputport==NULL)
  51.     exit(20);                          /* bomb if cannot open  */
  52.   mywindow = OpenWindow(&mynewwindow); /* open new window      */
  53.   if (mywindow == NULL)
  54.     exit (10);                         /* bomb if can't open   */
  55.   inputreq = CreateStdIO(inputport);   /* allocate IO request  */
  56.   if (inputreq == NULL)
  57.      exit(21);                         /* bomb if can't open   */
  58.   if (OpenDevice("input.device",0,(struct IORequest *)inputreq,0) != NULL)
  59.      exit(22);                         /* bomb if can't open device  */
  60.  
  61.   handlerptr.is_Code = hndstub;    /* set up Interrupt struct - point to  */
  62.   handlerptr.is_Data = NULL;       /* asm stub hndstub()                  */
  63.   handlerptr.is_Node.ln_Pri = 100; /* priority = 100 (max=127, Intui=50)  */
  64.  
  65.   inputreq->io_Command = IND_ADDHANDLER;  /* set up IO req */
  66.   inputreq->io_Data = (APTR)&handlerptr;
  67.   DoIO((struct IORequest *)inputreq);     /* install input handler */
  68.  
  69. /*  At this point the input handler is installed and doing its thing.
  70.     We will now wait until we get a CLOSEWINDOW message in the window's
  71.     IDCMP port */
  72.  
  73.   waitmask = (1 << mywindow->UserPort->mp_SigBit);  /* what to wait for */
  74.  
  75.   done = FALSE;
  76.   while (!done)             /*  keep looking for messages   */
  77.   {
  78.     Wait(waitmask);         /*  wait for IDCMP message      */
  79.     while ((m=GetMsg(mywindow->UserPort)) != NULL)  /* look at all msgs */
  80.     {
  81.       if (((struct IntuiMessage *)m)->Class == CLOSEWINDOW)
  82.         done = TRUE;        /*  if CLOSEWINDOW, we are done */
  83.       ReplyMsg(m);          /*  reply to all messages       */
  84.     }
  85.   }
  86.  
  87. /*  We have gotten the CLOSEWINDOW message - time to leave  */
  88.  
  89.   inputreq->io_Command = IND_REMHANDLER;    /* start packing up     */
  90.   DoIO((struct IORequest *)inputreq);       /* remove input handler */
  91.   CloseDevice((struct IORequest *)inputreq);/* close input device   */
  92.   DeleteStdIO(inputreq);                    /* delete IO request    */
  93.   DeletePort(inputport);                    /* delete message port  */
  94.   CloseWindow(mywindow);                    /* close the window     */
  95.   CloseLibrary((struct Library *)IntuitionBase);
  96.   exit(0);                                  /* Adios, Amigas!       */
  97.    
  98. }
  99.  
  100. /*  This function is called by the hndstub() assembly code interface
  101.     function, which is called whenever there is an input event.  The
  102.     hndstub() routine merely provides the assembly level interface to
  103.     the input event system, and stacks the data for this C language
  104.     handler.   */
  105.  
  106. struct InputEvent *hndcode(ie,data)
  107. struct InputEvent *ie;    /* the actual input event we want to examine */
  108. char *data;
  109. {
  110.   register struct InputEvent *e=ie;  /* register variable for speed */
  111.  
  112.   do    /* we want to modify mouse movement events - they are all  */
  113.   {     /* RAWMOUSE class events with a NOBUTTON code              */
  114.  
  115.     if (e->ie_Class == IECLASS_RAWMOUSE && e->ie_Code == IECODE_NOBUTTON)
  116.     {
  117.       e->ie_X = -e->ie_X;  /* if mouse movement event, reverse movement */
  118.       e->ie_Y = -e->ie_Y;
  119.     }
  120.     e = e->ie_NextEvent;
  121.   } while (e != NULL);    /* repeat if multiple event list */
  122.   return(ie);             /* pass event on down the line   */
  123. }
  124.  
  125. void MemCleanup() {}      /* dummy out function to save space (Lattice) */
  126.